package main
import ("fmt")

func main(){

	nextInt := intSeq()

	fmt.Println(nextInt())
	fmt.Println(nextInt())
	fmt.Println(nextInt())

	nextInt = intSeq()
	fmt.Println(nextInt())
	fmt.Println(nextInt())

	// 生成器
	pow3 := pow(3)
	res := pow3(3)
	fmt.Println("res:",res)

	pow4 := pow(4)
	res = pow4(2)
	fmt.Println("res:",res)
}

func intSeq() func()int{
	i := 0
	return func() int{
		i++
		return i
	}
}

// 实用：生成器
func pow(x int) func(int)int{
	return func(n int)int{
		total := 1
		for i:=0;i<x;i++{
			total *= n
		}
		return total
	}
}